package com.yuexun.beilunpatient.config;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by work-jx on 2015/12/16.
 */
public class CreateJson {

    //登录
    public static String Login_Json(String uid, String password) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_LOGIN);

            JSONObject request = new JSONObject();
            request.put("logid", uid);
            request.put("logpass", password);

            body.put("head", head);
            body.put("resquest", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }

    //病人列表
    public static String Patlist_Json(String wardno) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_PATLIST);

            JSONObject request = new JSONObject();
            request.put("wardno", wardno);

            body.put("head", head);
            body.put("resquest", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }

    //单个病人信息
    public static String Patinfo_Json(String visit_no) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_PATINFO);
            JSONObject request = new JSONObject();
            request.put("visit_no", visit_no);
            body.put("head", head);
            body.put("resquest", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }


    //病人检验申请单列表
    public static String Aslist_Json(String visit_no) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_AS_LIST);

            JSONObject request = new JSONObject();
            request.put("visit_no", visit_no);

            body.put("head", head);
            body.put("resquest", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }

    //病人检验报告单
    public static String Asrpt_Json(String requestno) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_AS_RPT);

            JSONObject request = new JSONObject();
            request.put("requestno", requestno);

            body.put("head", head);
            body.put("request", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }

    //病人检查申请单列表
    public static String Exlist_Json(String visit_no) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_EX_LIST);

            JSONObject request = new JSONObject();
            request.put("visit_no", visit_no);

            body.put("head", head);
            body.put("request", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }

    //病人检查报告单
    public static String Exrpt_Json(String requestno) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_EX_RPT);

            JSONObject request = new JSONObject();
            request.put("requestno", requestno);

            body.put("head", head);
            body.put("resquest", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }

    //病人费用清单查询
    public static String Patfee_Json(String visit_no, String startdate, String endate) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_PAT_FEE);

            JSONObject request = new JSONObject();
            request.put("visit_no", visit_no);
            request.put("startdate", startdate);
            request.put("enddate", endate);

            body.put("head", head);
            body.put("resquest", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }

    //获取病人当日可执行医嘱
    public static String Orderlist_Json(String visit_no) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_ORDER_LIST);

            JSONObject request = new JSONObject();
            request.put("visit_no", visit_no);

            body.put("head", head);
            body.put("resquest", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }


    //病人医嘱执行
    public static String Orderexec_Json(String visit_no, String barcode, int execempid, String exectime, String exectype) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_ORDER_EXEC);

            JSONObject request = new JSONObject();
            request.put("visit_no", visit_no);
            request.put("barcode", barcode);
            request.put("execempid", execempid);
            request.put("exectime", exectime);
            request.put("exectype", exectype);

            body.put("head", head);
            body.put("resquest", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }

    //病人检验标本采集
    public static String Ascollect_Json(String visitno, String barcode, int execempid, String exectime, String exectype) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_AS_COLLECT);

            JSONObject request = new JSONObject();
            request.put("visit_no", visitno);
            request.put("barcode", barcode);
            request.put("execempid", execempid);
            request.put("exectime", exectime);
            request.put("exectype", exectype);

            body.put("head", head);
            body.put("resquest", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }

    //登录_4.0,不需要密码
    public static String Login_NoPassword_Json(String uid) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_LOGIN_EXT);

            JSONObject request = new JSONObject();
            request.put("logid", uid);

            body.put("head", head);
            body.put("resquest", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }

    //获取病人所有医嘱
    public static String All_Orderlist_Json(String visit_no, String startdate, String endate) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
//            if(AppConfig.HISVerson == 5) {
//                head.put("trans_no", "kmhs_order_all");
//            }
//            else
//            {
            head.put("trans_no", AppConfig.MHS_ORDER_ALL);
//            }
            JSONObject request = new JSONObject();
            request.put("visit_no", visit_no);
            request.put("startdate", startdate);
            request.put("enddate", endate);

            body.put("head", head);
            body.put("resquest", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }

    //获取体征 HIS5.0
    public static String Signlist_Json(String inpNo, String interval, String date) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_ENR_LIST);

            JSONObject request = new JSONObject();
            request.put("inpNo", inpNo);
            request.put("interval", interval);
            request.put("date", date);

            body.put("head", head);
            body.put("request", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }

    //电子病历
    public static String CRP_Json(String visitno) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_EMR_CHD);

            JSONObject request = new JSONObject();
            request.put("visitNo", visitno);

            body.put("head", head);
            body.put("request", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }

    //获取血糖监测数据
    public static String BloodSugarlist_Json(String inpNo, String interval, String date) {
        JSONObject main = new JSONObject();
        try {
            JSONObject body = new JSONObject();
            JSONObject head = new JSONObject();
            head.put("userid", AppConfig.WEB_SERVICE_USER_ID);
            head.put("password", AppConfig.WEB_SERVICE_PASSWORD);
            head.put("trans_no", AppConfig.MHS_ENR_INFO);

            JSONObject request = new JSONObject();
            request.put("inpNo", inpNo);
            request.put("interval", interval);
            request.put("date", date);
            request.put("templateId", "29");

            body.put("head", head);
            body.put("request", request);
            main.put("body", body);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }


    //远程日志
    public static String LOG_JSON(String url, String type, String params, String result) {
        JSONObject main = new JSONObject();
        try {
            main.put("url", url);
            main.put("type", type);
            main.put("params", params);
            main.put("result", result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return main.toString();
    }

}
